<template>
	<view>
		<!-- <view class="top">
			<u-button class="top-left" size="mini" type="primary" @click="goAdd()">新增</u-button>
			<u-button class="top-right" size="mini" type="warning">编辑</u-button>
		</view> -->
		<view class="loading">
			<u-loading mode="circle" :show="loading" size="40"></u-loading>
		</view>
		<u-empty text="还没有收货地址哦,快去添加吧" mode="address" v-if="list.length == 0"></u-empty>
		<swiper-item class="swiper-item">
			<scroll-view scroll-y style="height:100%;width: 100%;">
				<!-- @scrolltolower= -->
				<view class="page-box">
					<view v-for="item in list">
						<u-card :head-border-bottom="false" :foot-border-top="false" padding="20"
							@click="toAddressDetail(item)">
							<view class="" slot="body">
								<view class="head-container">
									<view>
										<text class="name">收货人: {{item.name}}</text>
										<text class="head-title">性别:
											<text v-if="item.sex == 0">男</text>
											<text v-else-if="item.sex == 1">女</text>
											<text v-else>保密</text>
										</text>
									</view>
									<view class="two">
										<text class="phone">手机号: {{item.phone}}</text>
										<text class="head-title">是否默认:
											<text v-if="item.isDefault == 0">否</text>
											<text v-else>是</text>
										</text>
									</view>
								</view>
							</view>
							<view class="" slot="foot">
								<view style="display: flex; flex-wrap: wrap;">
									<view class="item-container">
										<text class="label">详细地址: {{item.detailAddress}}</text>
									</view>

								</view>

							</view>
						</u-card>
					</view>
					<view class="address-add">
						<u-button @click="goAdd()">点击新增</u-button>
					</view>
				</view>
			</scroll-view>


		</swiper-item>
	</view>
</template>

<script>
	import {
		getAddress
	} from '@/api/system/address/address'
	export default {
		data() {
			return {
				loading: true,
				list: []
			}
		},
		mounted() {
			getAddress().then(res => {
				this.list = res.rows;
				this.loading = false
				// console.log(res)
				// console.log(this.list)
			})
		},
		onShow() {
			getAddress().then(res => {
				this.list = res.rows;
				console.log(res)
				// console.log(this.list)
			})
		},
		methods: {
			// 跳转添加
			goAdd() {
				this.$tab.navigateTo('/pages/address/add');
			},
			// 点击单个地址
			toAddressDetail(item) {
				this.$tab.navigateTo('/pages/address/update?item=' + encodeURIComponent(JSON.stringify(item)));
			}

		}
	}
</script>

<style>
	
	.loading{
		text-align: center;
		margin-top: 15px;
		margin-bottom: 15px;
	}
	
	.swiper-item {
		height: 80%;
	}

	.address-add {
		margin-left: 13%;
		padding-bottom: 10%;
		width: 74%;
	}

	.top {
		display: grid;
		grid-template-columns: 1fr 1fr;
		padding-top: 0.5vh;
		padding-left: 5vw;
		padding-right: 5vw;
		width: 100%;
		background-color: ghostwhite;
		height: 4.5vh;
	}

	.top-left {
		margin-left: 0vw;
	}

	.top-right {
		text-align: right;
		margin-right: 0vw;
	}

	.name {
		/* width: 15vw; */
		margin-right: 18vw;
	}

	.head-title {
		margin-right: 8vw;
	}

	.two {
		margin-top: 1vh;
	}

	.phone {
		margin-right: 10vw;
	}
</style>